~ function() {
    var root,
        default_option,
        idExpr = /^\s*#([\w-]*)$/,
        vendors = ['t', 'WebkitT', 'OT', 'MozT'],
        vendor,
        wordList,
        config,
        cell = function(options) {
            this.init(options);
        };
    cell.fn = cell.prototype;
    cell.fn.init = function(opts) {
        if (!vendor) {
            this.canTransition();
        }
        this.extend(default_option, opts);
        wordList = vendors.slice.call(default_option.target.children, 0);
        this.render(default_option.words.substr(0, wordList.length));
    }
    cell.fn.extend = function(dest, src) {
        for (var i in src) {
            dest[i] = src[i];
        }
    };
    //query
    cell.fn.find = function(path) {
        var match;
        if (typeof path !== 'string') {
            return [];
        }
        //ie 8+
        if (root.querySelectorAll) {
            return root.querySelectorAll(path);
        } else {
            match = idExpr.exec(path);
            if (match && match[1]) {
                return [root.getElementById(match[1])];
            }
            return [];
        }
    };
    //array
    cell.fn.isArray = function(o) {
        if (vendors.isArray) {
            return vendors.isArray(o);
        } else {
            return config.toString.call(o).indexOf('Array') != -1;
        }
    };
    cell.fn.isNum = function(n) {
        return !isNaN(n);
    };
    cell.fn.isLetter = function(c) {
        var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
            'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
        ];
        return arr.indexOf(c.toLowerCase()) != -1;
    };
    //number
    cell.fn.number = {
        //fake receipt
        0: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 1, 1, 0, 0, 0],
            [0, 0, 1, 0, 1, 0, 1, 0, 0, 0],
            [0, 0, 1, 1, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        1: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        2: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        3: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        4: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        5: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        6: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        7: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        8: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        9: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]
    };
    //letter
    cell.fn.letter = {
        //fake receipt
        A: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
            [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
            [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
            [0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
            [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
            [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
            [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ],
        K: [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
            [0, 0, 0, 1, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
            [0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]
    };
    root = document;
    default_option = {
        target: '', //必须给元素
        words: 'AK',
        baseWidth: 20, //基础元素的宽度
        shape: 'square', //形状
        space: 10, //基础元素间距
        color: '#000', //基础元素颜色
        directionIn: 'up', //滚入方向
        directionOut: 'down', //滚出方向
        vertical: false, //字横着还是竖着
        // wrpper_className: '',
        effect: ''
    };
    config = {
        matrix: {
            w: 10,
            h: 10,
            empty: 0,
            exist: 1
        }
    };
    wordList = [];
    cell.fn.canTransition = function() {
        //ie 10+
        var i = 0,
            d = document.createElement('div');
        for (; i < vendors.length; i++) {
            if ((vendors[i] + 'ransition') in d.style) {
                vendor = vendors[i];
                return true;
            }
        }
        return false;
    };
    //render
    cell.fn.render = function(words, index) {
        var i = index || 0,
            j = 0,
            k = 0,
            cells = null,
            cell = null,
            cssStr = '',
            flag, fragment;
        if (words && words.length != 0 && (this.isArray(words) || typeof words == 'string')) {
            fragment = root.createDocumentFragment();
            for (; i < ((index + 1) || words.length); i++) {
                cells = wordList[i];
                //clear
                cells.innerHTML = '';
                cells.style.height = cells.style.width = ((default_option.baseWidth + default_option.space) * config.matrix.w - default_option.space) + 'px';
                cssStr = 'position:absolute;width:' + default_option.baseWidth +
                    'px;height:' + default_option.baseWidth + 'px;background:' + default_option.color;
                for (j = 0; j < config.matrix.w; j++) {
                    for (k = 0; k < config.matrix.h; k++) {

                        if (this.isLetter(words[i])) {
                            flag = this.letter[words[i]];
                        } else if (this.isNum(words[i])) {
                            flag = this.number[words[i]];
                        }

                        if (flag[j][k] == config.matrix.exist) {
                            cell = root.createElement('div');
                            cell.style.cssText = cssStr + ';top:' + j * (default_option.baseWidth + default_option.space) +
                                'px;left:' + k * (default_option.baseWidth + default_option.space) + 'px';
                            if (this.canTransition()) {
                                cell.style.cssText += ';transform:translate(0,-300px) translateZ(0);-webkit-transform:translate(0,-300px) translateZ(0);' + 'transition:0s;-webkit-transition:0s;';
                            }
                            cells.appendChild(cell);
                        }
                    }
                }
                fragment.appendChild(cells);
            }
            default_option.target.appendChild(fragment);
        }
    };
    //set words[i]
    cell.fn.set = function(i, newc, flag) {
        //flag 是否要强制修改
        var _this = this;
        if (!this.isArray(default_option.words)) {
            default_option.words = default_option.words.split('');
        }
        if (!flag && default_option.words[i] == String(newc)) {
            return;
        }
        default_option.words[i] = String(newc);
        this.render(default_option.words, i);
        setTimeout(function() {
            _this.reset(i);
            _this.run(null, i);
        }, 30);
    };
    //run
    cell.fn.run = function(effect) {
        effect = (effect && typeof effect == 'string') || 'default';
        if (this.move[effect]) {
            this.move[effect].apply(this, vendors.slice.call(arguments, 1));
        }
    };
    cell.fn.move = {
        default: function(index, pos1, pos2, speed, last) {
            var i = 0,
                j, cells, cell;
            if (this.canTransition()) {
                for (i = (index || 0); i < ((index + 1) || wordList.length); i++) {
                    cells = wordList[i].children;
                    for (j = 0; j < cells.length; j++) {
                        cell = cells[j];
                        cell.style.cssText += ';transform:translate(0,0) translateZ(0);-webkit-transform:translate(0,0) translateZ(0);';
                        last = Math.random() * 1;
                        cell.style.cssText += 'transition:' + last + 's;-webkit-transition:' + last + 's;';
                    }
                }
            } else {
                //sorry
            }
        }
    };
    cell.fn.reset = function(index) {
        if (this.canTransition()) {
            for (i = (index || 0); i < ((index + 1) || wordList.length); i++) {
                cells = wordList[i].children;
                for (j = 0; j < cells.length; j++) {
                    cell = cells[j];
                    cell.style.cssText += ';transform:translate(0,-300px) translateZ(0);-webkit-transform:translate(0,-300px) translateZ(0);';
                }
            }
        } else {

        }
    };
    window.cell = cell;
}();
